/*
 *  UI_Panel.cpp
 *
 *	Date: 2011-12-19
 *  Author: linshenqi
 */
 
#include "./GUI.h"
#include <stdlib.h>

enum
{
	ID_BTN1 = 0,
	ID_BTN2
};

BEGIN_EVENT_TABLE(GUI_Panel, wxPanel)
	//EVT_PAINT(UI_Panel::OnPaint)
	EVT_BUTTON(ID_BTN1, GUI_Panel::B1)
	EVT_BUTTON(ID_BTN2, GUI_Panel::B2)
END_EVENT_TABLE()


GUI_Panel::GUI_Panel(wxWindow *pParent)
: m_pCmb(NULL)
{
	m_pBtn[0] = NULL;
	m_pBtn[1] = NULL;
	this->SetSize(pParent->GetSize().GetWidth(), pParent->GetSize().GetHeight());
	this->Create(pParent);
	::wxInitAllImageHandlers();
	pBuffer = new wxBitmap(658, 696);
	this->m_fX = double(double(658) / double(this->GetSize().GetWidth()));
	this->m_fY = double(double(696) / double(this->GetSize().GetHeight()));
	Init();
}

GUI_Panel::~GUI_Panel()
{}

void GUI_Panel::B1(wxCommandEvent& event)
{
	printf("button%d clicked\n", ID_BTN1);
}

void GUI_Panel::B2(wxCommandEvent& event)
{
	printf("button%d clicked\n", ID_BTN2);
}
	
void GUI_Panel::Init()
{
	if(!m_pBtn[0])
		m_pBtn[0] = new GUI_Button(this, ID_BTN1);
		
	m_pBtn[0]->Move(100, 100);
	
	m_pBtn[1] = new GUI_Button(this, ID_BTN2);
	m_pBtn[1]->Move(200, 200);
	
	m_pCmb = new GUI_ComboBox(this);
	m_pCmb->Move(300, 300);
}

void GUI_Panel::OnPaint(wxPaintEvent& evt)
{
	wxPaintDC dc(this);
	wxMemoryDC memdc;
	
	memdc.SelectObject(*pBuffer);
	dc.SetUserScale(m_fX, m_fY);
	dc.Blit(0, 0, pBuffer->GetWidth(), pBuffer->GetHeight(), &memdc, 0, 0, wxCOPY, true);
	memdc.SelectObject(wxNullBitmap);
}